package mysql

import (
	"gorm.io/gorm"
	"learning-pass/common/proto/user"
)

type StudyPlan struct {
	gorm.Model
	UserId     int64  `gorm:"type:int;" json:"userId"`
	StartTime  string `gorm:"type:datetime;" json:"start_time"`
	CourseName string `gorm:"type:varchar(100)" json:"course_name"`
}

func (s *StudyPlan) AddStudyPlan(in *user.AddUserStudyPlanReq) error {
	stu := &StudyPlan{
		UserId:     in.UserId,
		StartTime:  in.StartTime,
		CourseName: in.Course,
	}
	err := DB.Create(&stu).Error
	if err != nil {
		return err
	}
	return nil
}
func (s *StudyPlan) FindStudyPlanById(id int64) (*StudyPlan, error) {
	err := DB.Where("id=?", id).Find(&s).Error
	if err != nil {
		return nil, err
	}
	return s, nil
}
func (s *StudyPlan) DelStudyPlan(userId, id int64) error {
	err := DB.Model(&s).Where("user_id=?", userId).Delete("id", id).Error
	if err != nil {
		return err
	}
	return nil
}
